package com.oliver.oliveraiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.document.Document;
import org.springframework.ai.transformer.KeywordMetadataEnricher;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName MyKeywordEnricher
 * @Description TODO
 * @Author snow
 * @Date 2025/5/22 0:04
 **/

/**
 * 基于 AI 的文档元信息增强器
 */
@Component
public class MyKeywordEnricher {

    @Resource
    private ChatModel dashscopeChatModel;

    List<Document> enrich(List<Document> documents) {
        //  为文档自动生成5个元信息
        KeywordMetadataEnricher enricher = new KeywordMetadataEnricher(dashscopeChatModel, 5);
        return enricher.apply(documents);
    }

}
